package dataStructures;

public class ChainedHashTableIterator<K,V> implements Iterator<Entry<K,V>>{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private  Dictionary<K,V>[] data;
    private int current;


	private Iterator<Entry<K,V>> it;
	private boolean verificator;
    
    public ChainedHashTableIterator(Dictionary<K,V>[] inputData) {
        this.data = inputData;
        current = 0;
        verificator = false;
        it = null;
    }
    
	@Override
	public boolean hasNext() {
		// TODO Auto-generated method stub
		return data.length != current && data.length>=current;
	}
	@Override
	public Entry<K,V> next() throws NoSuchElementException {
		// TODO Auto-generated method stub
		Entry<K,V> valueReturn;
		if(!verificator)
		{
			while(hasNext()) {
				Dictionary<K,V> aux = data[current++];
				 it = aux.iterator();
				while(it.hasNext()){
					valueReturn = it.next();
					verificator = hasNext();
					return valueReturn;
				}
	        }	
		}
		else
		{
			valueReturn = it.next();
			verificator = hasNext();
			return valueReturn;
		}
		new NoSuchElementException();
		return null;
	}

	@Override
	public void rewind() {
		// TODO Auto-generated method stub
		current = 0;
	}

}
